#pragma GCC optimize(2)
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <map>
#include <vector>

using namespace std;
using LL = long long;
const int N = 30, M = 2e5 + 10;

int n;
vector<int> mp[N];
char str[M];
vector<int> res;

int main(){
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    int T;
    scanf("%d", &T);
    while(T--){
        for(int i = 0; i < N; i ++) mp[i].clear();
        res.clear();


        scanf("%s", str + 1);
        n = strlen(str + 1);


        
        for(int i = 1; i <= n; i ++){
            mp[str[i] - 'a'].push_back(i);
        }



        int cost = abs(str[n] - str[1]);
        int cnt = 0;

   


        int x2 = str[n] - 'a', x1 = str[1] - 'a';

 
        if(x1 <= x2){
            for(int i = x1; i <= x2; i ++){

                if(mp[i].empty()) continue;
                cnt += mp[i].size();
                for(int j = 0; j < mp[i].size(); j ++){
                    res.push_back(mp[i][j]);
                }
            }
        }else{

            for(int i = x1; i >= x2; i --){

                if(mp[i].empty()) continue;
                cnt += mp[i].size();
                for(int j = 0; j < mp[i].size(); j ++){
                    res.push_back(mp[i][j]);
                }
            }
        }



        printf("%d %d\n", cost, cnt);
        for(int i = 0; i < res.size(); i ++){
            printf("%d ", res[i]);
        }
        printf("\n");
        
    }
    
    return 0;
}